<template>
  <el-form :model="formData" label-width="120px">
    <el-form-item label="名称">
      <el-input v-model="formData.name" />
    </el-form-item>
    <el-form-item label="图片">
      <Tuku v-model="formData.img"></Tuku>
    </el-form-item>
    <el-form-item label="父类">
     <CategoryTree v-model="formData.parentId"></CategoryTree>
    </el-form-item>
    <el-form-item label="排序">
      <el-input-number v-model="formData.seq" :min="1" :max="99" />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onSubmit">添加</el-button>
    </el-form-item>
  </el-form>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from "vue"
import Tuku from "@/components/Tuku.vue";
import { ElMessage } from 'element-plus'
import { categoryApi } from '@/api'

import CategoryTree from "@/components/CategoryTree.vue";
const formData = reactive({
  name: "",
  img: "",
  seq: 1,
  parentId: 0
})

onMounted(() => {

  // let henan = ["烩面", "道口烧鸡", "胡辣汤", "灌汤包", "花生糕", "黄牛肉"]
  // let eatFoods = henan.reduce((duzi: any, currentValue: any) => {
  //   if (currentValue == "道口烧鸡") { duzi.push(currentValue) }
  //   if (currentValue == "黄牛肉") { duzi.push(currentValue) }
  //   return duzi;
  // }, [])
  // console.log(eatFoods);

})


const onSubmit = () => {

  categoryApi.insert.call(formData).then(() => {

    ElMessage.success('添加成功')
    //callCategoryApi()
  })


}

</script>